<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
	table,tr,td,th{
		border:1px solid black;
	}
</style>
</head>
<body>
	<form action="QueryStuServlet" method="post">
		<table>
			<thead>
				<tr>
					<td colspan="6">
						姓名:<input type="text" name="sName" placeholder="Ender Name"/>&nbsp;&nbsp;
						性别:<select name="sGender">
								<option value="">----请选择 ----</option>
								<option value="男">男</option>
								<option value="女">女</option>
							</select>&nbsp;&nbsp;
							<input type="submit" value="查询" />
							<input type="button" onclick="doAddStu()" value="添加学生"/>
					</td>
				</tr>
				<tr>
				<th>编号</th>
				<th>姓名</th>
				<th>年龄</th>
				<th>性别</th>
				<th>爱好</th>
				<th>操作</th>
				</tr>
			</thead>
			<tbody>
				<c:if test="${empty pageBean.list}"></c:if>
				<c:if test="${not empty pageBean.list}">
					<c:forEach items="${pageBean.list}" var="stu">
						<tr align="center">
							<td>${stu.sId}</td>
							<td>${stu.sName}</td>
							<td>${stu.sAge}</td>
							<td>${stu.sGender}</td>
							<td>${stu.sHobby}</td>
							<td>
							<a href="javascript:void(0)" onclick="doUpdateStu(${stu.sId})">修改</a>
							<a href="javascript:void(0)" id="delStu" onclick="doDeleteStu(${stu.sId})">删除</a>
							</td>
						</tr>
					</c:forEach>
				</c:if>
			</tbody>
			<tfoot>
				<tr align="center"><td colspan="6">
					第${pageBean.currentPage}/${pageBean.totalPage}页
					<c:if test="${pageBean.currentPage != 1}">
						<a href="GoStuListPageServlet?currentPage=1">首页</a>
						<a href="GoStuListPageServlet?currentPage=${pageBean.currentPage-1}">上一页</a>
					</c:if>
					<c:forEach step="1" begin="1" end="${pageBean.totalPage}" var="i">
						<c:if test="${i!=pageBean.currentPage}">
							<a href="GoStuListPageServlet?currentPage=${i}">${i}</a>
						</c:if>
						<c:if test="${i == pageBean.currentPage}">
							${i}
						</c:if>
					</c:forEach>
					<c:if test="${pageBean.currentPage != pageBean.totalPage}">
						<a href="GoStuListPageServlet?currentPage=${pageBean.currentPage+1}">下一页</a>
						<a href="GoStuListPageServlet?currentPage=${pageBean.totalPage}">尾页</a>
					</c:if>
				</td></tr>
			</tfoot>
		</table>
	</form>
	<script src="js/jquery-3.4.1.min.js"></script>
	<script>
		function doAddStu(){
			location.href="GoAddStuUi";
		}
		function doDeleteStu(sId){
			var flag = confirm("是否确认删除");
			if(flag){
				location.href="DelStuServlet?sId="+sId;
			}	
		}
		function doUpdateStu(sId){
			location.href="FindStuServlet?sId="+sId;
		}
	</script>
</body>
</html>